<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    
    <form id="DataForm" action="" method="POST" class="layui-form layui-form-pane">
        <div class="layui-tab layui-tab-brief" lay-filter="itemTab">

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <!-- <div class="layui-form-item">
                        <label class="layui-form-label">跳转代理商</label>
                        <div class="layui-input-inline">
                            <input type="text"  placeholder="请选择跳转代理商" autocomplete="off" class="layui-input" id="agent_select" value="{:empty($agent['name']) ? '' : $agent['name']}">
                            <input type="hidden"  autocomplete="off" class="layui-input" id="store_id" name="info[store_id]" value="{:empty($agent['id']) ? '' : $agent['id']}">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">跳转商家</label>
                        <div class="layui-input-inline">
                            <input type="text"  placeholder="请选择跳转商家" autocomplete="off" class="layui-input" id="store_select" value="{:empty($store['title']) ? '' : $store['title']}">
                            <input type="hidden"  autocomplete="off" class="layui-input" id="store_id" name="info[store_id]" value="{:empty($store['id']) ? '' : $store['id']}">
                        </div>
                    </div> -->

                    <div class="layui-form-item">
                        <label class="layui-form-label">跳转商品</label>
                        <div class="layui-input-inline">
                            <input type="text"  placeholder="请选择商品" autocomplete="off" class="layui-input" id="goods_select" value="{$info['goods_title']}">
                            <input type="hidden"  autocomplete="off" class="layui-input" id="goods_id" name="info[goods_id]" value="{$info['goods_id']}">
                        </div>
                        <!-- <div class="layui-form-mid layui-word-aux">默认不跳转</div> -->
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[title]" placeholder="请输入标题" autocomplete="off"
                                class="layui-input" value="{$info['title']}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片</label>
                        <div class="layui-input-inline" style="width: 500px;">
                            <input type="text" name="info[image]" id="image" value="{$info['image']}" autocomplete="off"
                                class="layui-input layui-col-xs6" readonly>
                            <div class="layuimini-upload-btn">
                                <button type="button" class="layui-btn" id="upload_image"><i
                                        class="fa fa-upload"></i>
                                    上传图片</button>
                            </div>
                        </div>
                        <div class="layui-form-mid layui-word-aux">建议尺寸 750*350mm </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="number" name="info[sort]" placeholder="请输入排序" autocomplete="off"
                                class="layui-input" value="{$info['sort']}">
                        </div>
                    </div>
      
                    <div class="layui-form-item">
                        <input type="hidden" name="id" value="{$info['id']}">
                        <div class="layui-input-block" style="margin:auto;text-align: center;">
                            <button id="saveButton" type="submit" class="layui-btn"><i class="fa fa-check"></i>
                                提交</button>
                            <button id="closeButton" type="button" class="layui-btn layui-btn-primary"><i
                                    class="fa fa-close"></i>
                                关闭</button>
                        </div>
                    </div>
                </div>

              

            </div>
        </div>
    </form>
</div>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
      layui.use(['layer', 'form', 'laydate', 'element', 'upload','tableSelect'], function () {
        var    tableSelect = layui.tableSelect;
        var $ = layui.$, layer = layui.layer, table = layui.table,  element = layui.element,laydate = layui.laydate, form = layui.form, upload = layui.upload;
        var indexFrame = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $("#saveButton").on('click', function () {
            var loading = layer.open({ type: 3 });
            $.ajax({
                url: "{:url('edit')}",
                type: 'post',
                data: $("#DataForm").serialize(),
                success: function (data) {
                    console.log(data);
                    layer.close(loading);
                    if (data.code == 0) {
                        parent.tableReload();
                        parent.layer.close(indexFrame);
                        parent.layer.msg(data.msg);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            })
            return false;
        })

        $("#closeButton").on('click', function () {
            parent.layer.close(indexFrame);
        })

        // 分步表单下一步
        $(".downButton").on('click', function () {
            var id = $(".layui-this").next().attr('lay-id');
            element.tabChange('itemTab', id);
        });
        // 分步表单上一步
        $(".upButton").on('click', function () {
            var id = $(".layui-this").prev().attr('lay-id');
            element.tabChange('itemTab', id);
        });

        upload.render({
                elem: '#upload_image', url: "{:url('common/images')}", done: function (res) {
                    $("#image").val(res.data.name);
                        layer.msg(res.msg);
                }
        });
        tableSelect.render({
            elem: '#agent_select',
            checkedKey: 'id',
            searchKey: 'name',
            table: {
                url: '/admin/agent.agent/list',
                cols: [[
                    { type: 'radio' },
                    { field: 'id', title: 'ID' },
                    { field: 'name', title: '代理商名称' },
                    { field: 'username', title: '用户名' }
                ]]
            },
            done: function (elem, data) {
                var idArr = []
                var name = []
                layui.each(data.data, function (index, item) {
                    name.push(item.name)
                    idArr.push(item.id);
                })
                $("#agent_id").val(idArr.join(","));
                console.log(name);
                $("#agent_select").val(name.join(","));
            }
        })
        tableSelect.render({
            elem: '#goods_select',
            checkedKey: 'id',
            searchKey: 'name',
            table: {
                url: '/admin/goods.goods/list',
                cols: [[
                    { type: 'radio' },
                    { field: 'id', title: 'ID' },
                    { field: 'title', title: '名称' },
                ]]
            },
            done: function (elem, data) {
                var idArr = []
                var name = []
                layui.each(data.data, function (index, item) {
                    name.push(item.title)
                    idArr.push(item.id);
                })
                $("#goods_id").val(idArr.join(","));
                console.log(name);
                $("#goods_select").val(name.join(","));
            }
        })
     
        });
</script>
</body>
</html>